define(['jquery', 'bootstrap', 'backend', 'table', 'form'], function($, undefined, Backend, Table, Form) {

	var Controller = {
		index: function() {
			// 初始化表格参数配置
			Table.api.init({
				extend: {
					index_url: 'wanlshop/refund/index' + location.search,
					add_url: '',
					edit_url: '',
					del_url: '',
					multi_url: '',
					table: 'wanlshop_refund',
				}
			});

			var table = $("#table");

			// 初始化表格
			table.bootstrapTable({
				url: $.fn.bootstrapTable.defaults.extend.index_url,
				pk: 'id',
				sortName: 'id',
				showColumns: false,
				showToggle: false,
				showExport: false,
				search:false,
				fixedColumns: true,
                fixedRightNumber: 1,
				columns: [
					[
						{checkbox: true},
						{field: 'id', title: __('Id'),operate: false},
						{field: 'order.order_no', title: __('Order.order_no')},
						{field: 'shop.id', title: __('店铺'),searchList:$.getJSON('Ajax/getshoplist?type=arr'), visible:false},
						{field: 'shop.shopname', title: __('门店'),operate: false},
						{field: 'goods_name', title: __('Goods_name'),operate: false},
						{field: 'price', title: __('Price'),operate: false},
						{field: 'state', title: __('State'), searchList: {"0":__('State 0'),"1":__('State 1'),"2":__('State 2'),"3":__('State 3'),
								"4":__('State 4'),"5":__('State 5'),"6":__('State 6'),"7":__('State 7'),"8":__('State 8')}, formatter: Table.api.formatter.normal,operate: false},
						{field: 'refund_detail', title: __('Refund_detail'),operate: false},
						{field: 'createtime', title: __('Createtime'), operate:'RANGE', addclass:'datetimerange', formatter: Table.api.formatter.datetime},
						{field: 'completetime', title: __('Completetime'), operate:'RANGE', addclass:'datetimerange', formatter: Table.api.formatter.datetime},
					]
				]
			});

			// 为表格绑定事件
			Table.api.bindevent(table);
		},
		detail: function () {
		 //    $(document).on("click", ".btn-agree", function () {
			// 	Fast.api.ajax({
			// 		url:'wanlshop/refund/agree?ids='+Backend.api.query('ids'),
			// 	}, function(data, ret){
			// 		Layer.closeAll();
			// 		return false;
			// 	});
		 //    });
			// $(document).on("click", ".btn-refuse", function () {
				
			// });
		},
		refuse: function () {
		    Controller.api.bindevent();
		},
		api: {
			bindevent: function() {
				Form.api.bindevent($("form[role=form]"));
			},
			formatter: {
				goods: function(value, row, index) {
					if(row.order_type === 'groups'){
						var image = Fast.api.cdnurl(row.groupsgoods.image);
						return '<a href="javascript:" style="margin-right: 6px;"><img class="img-sm img-center" src="' + image +'"></a>' + row.groupsgoods.title;
					}else{
						var image = Fast.api.cdnurl(row.goods.image);
						return '<a href="javascript:" style="margin-right: 6px;"><img class="img-sm img-center" src="' + image +'"></a>' + row.goods.title;
					}
				}
			}
		}
	};
	return Controller;
});